package com.new_wear.project.system.enforcement.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.new_wear.framework.aspectj.lang.annotation.Log;
import com.new_wear.framework.aspectj.lang.enums.BusinessType;
import com.new_wear.project.system.enforcement.domain.Enforcement;
import com.new_wear.project.system.enforcement.service.IEnforcementService;
import com.new_wear.framework.web.controller.BaseController;
import com.new_wear.framework.web.domain.AjaxResult;
import com.new_wear.common.utils.poi.ExcelUtil;
import com.new_wear.framework.web.page.TableDataInfo;

/**
 * 执法人员信息Controller
 * 
 * @author new_wear
 * @date 2019-12-23
 */
@Controller
@RequestMapping("/system/enforcement")
public class EnforcementController extends BaseController
{
    private String prefix = "system/enforcement";

    @Autowired
    private IEnforcementService enforcementService;

    @RequiresPermissions("system:enforcement:view")
    @GetMapping()
    public String enforcement()
    {
        return prefix + "/enforcement";
    }

    /**
     * 查询执法人员信息列表
     */
    @RequiresPermissions("system:enforcement:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Enforcement enforcement)
    {
        startPage();
        List<Enforcement> list = enforcementService.selectEnforcementList(enforcement);
        return getDataTable(list);
    }

    /**
     * 导出执法人员信息列表
     */
    @RequiresPermissions("system:enforcement:export")
    @Log(title = "执法人员信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Enforcement enforcement)
    {
        List<Enforcement> list = enforcementService.selectEnforcementList(enforcement);
        ExcelUtil<Enforcement> util = new ExcelUtil<Enforcement>(Enforcement.class);
        return util.exportExcel(list, "enforcement");
    }

    /**
     * 新增执法人员信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存执法人员信息
     */
    @RequiresPermissions("system:enforcement:add")
    @Log(title = "执法人员信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Enforcement enforcement)
    {
        return toAjax(enforcementService.insertEnforcement(enforcement));
    }

    /**
     * 修改执法人员信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Enforcement enforcement = enforcementService.selectEnforcementById(id);
        mmap.put("enforcement", enforcement);
        return prefix + "/edit";
    }

    /**
     * 修改保存执法人员信息
     */
    @RequiresPermissions("system:enforcement:edit")
    @Log(title = "执法人员信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Enforcement enforcement)
    {
        return toAjax(enforcementService.updateEnforcement(enforcement));
    }

    /**
     * 删除执法人员信息
     */
    @RequiresPermissions("system:enforcement:remove")
    @Log(title = "执法人员信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(enforcementService.deleteEnforcementByIds(ids));
    }
}
